<?php

namespace App\Exception;

use Throwable;

class ApiException extends \Exception
{
    /**
     * 未知错误.
     */
    const UNKNOWN = 9999;

    /**
     * 认证相关.
     */
    const AUTH_FAILED = 1000;

    /**
     * 客户端参数错误相关.
     */
    const INVALID_PARAMS = 2000;
    const ONLY_ALLOW_ONE_ZERO_DEPT_PID = 2001;
    const SAME_RECORD_FOUND = 2002;
    const RECORD_NOT_FOUND = 2003;

    /**
     * 文件相关.
     */
    const FILE_UPLOAD_FAILED = 3000;

    /**
     * 系统错误相关，但不足以影响运行.
     */
    const MULTI_RESULT_FOUND = 5000;

    /**
     * raw.
     *
     * @var array
     */
    public $raw;

    /**
     * Bootstrap.
     *
     * @author yansongda <me@yansongda.cn>
     *
     * @param string         $message
     * @param int            $code
     * @param array|string   $raw
     * @param Throwable|null $previous
     */
    public function __construct(string $message = '', int $code = self::UNKNOWN, $raw = [], Throwable $previous = null)
    {
        $message = $message === '未知错误' ?  : $message;
        $this->raw = is_array($raw) ? $raw : [$raw];

        parent::__construct($message, $code, $previous);
    }
}
